import axiosServer from '@/utils/request'

/**
 * 商品列表
 * @returns
 */
export const RequestProductList = (pageNo = 1, pageSize = 10,shopKey,productKey) => {
	return axiosServer({
		method: 'get',
		params: {
			pageNo,
			pageSize,
			shopKey,
			productKey
		},
		url: '/api/shop/list',
	})
}
/**
 * 商品分类
 * @returns
 */
export const RequestCategoryList = () => {
	return axiosServer({
		method: 'get',
		url: '/api/shop/category/list',
	})
}
/**
 * 商品添加
 * @returns
 */
export const RequestProductAdd = product => {
	return axiosServer({
		method: 'post',
		data: {
			categoryId: product.categoryId,
			product: product.name,
			picture: product.picture,
			price: product.price,
			oldprice: product.oldprice,
			putaway: product.putaway,
			detail: product.detail,
			shop: product.shop,
		},
		url: '/api/shop/add',
	})
}

/**
 * 商品删除
 * @returns
 */
export const RequestProductDeleteById = id => {
	return axiosServer({
		method: 'get',
		url: '/api/shop/delete?id=' + id,
	})
}

/**
 * 商品上下架
 * @returns
 */
export const RequestProductPutAway = (id, putaway) => {
	return axiosServer({
		method: 'get',
		params: {
			id,
			putaway,
		},
		url: '/api/shop/putaway',
	})
}

/**
 * 根据ID查找商品
 */
export const RequestProductById = id => {
	return axiosServer({
		method: 'get',
		params: {
			id,
		},
		url: '/api/shop/find',
	})
}

/**
 * 商品修改
 * @returns
 */
export const RequestProductUpdate = product => {
	return axiosServer({
		method: 'post',
		data: {
			id: product.id,
			categoryId: product.categoryId,
			product: product.name,
			picture: product.picture,
			price: product.price,
			oldprice: product.oldprice,
			putaway: product.putaway,
			detail: product.detail,
			shop: product.shop,
		},
		url: '/api/shop/update',
	})
}


/**
 * 批量删除
 */
 export const RequestProductBatchDelete = ids => {
	return axiosServer({
		method: 'get',
		params: {
			ids
		},
		url: '/api/shop/batchdelete',
	})
}

/**
 * 上传单文件
 * headerImg: File
 */
 export const RequestUploadFile = formdata => {
	return axiosServer({
		method: 'post',
		data:formdata,
		headers: {'Content-Type':'multipart/form-data'},
		url: '/api/uploadFile',
	})
}
